package org.finesys.common.mp.core.constants;

import lombok.Getter;

/**
 * 查询条件常量类
 */
@Getter
public enum QueryWrapperEnum {

    EQ(QueryWrapperConstants.EQ, "equal"), // 等于
    NEQ(QueryWrapperConstants.NEQ, "neq"), // 不等于
    GT(QueryWrapperConstants.GT, "gt"), // 大于
    GTE(QueryWrapperConstants.GTE, "gte"), // 大于等于
    LT(QueryWrapperConstants.LT, "lt"), // 小于
    LTE(QueryWrapperConstants.LTE, "lte"), // 小于等于
    LIKE(QueryWrapperConstants.LIKE, "like"), // 模糊查询
    L_LIKE(QueryWrapperConstants.L_LIKE, "leftLike"), // 左侧模糊
    R_LIKE(QueryWrapperConstants.R_LIKE, "rightLike"), // 右侧模糊
    N_LIKE(QueryWrapperConstants.N_LIKE, "notLike"), // 不匹配模糊
    NULL(QueryWrapperConstants.NULL, "null"), // 空
    NOTNULL(QueryWrapperConstants.NOTNULL, "notNull"), // 不为空
    BETWEEN(QueryWrapperConstants.BETWEEN, "between"), // 区间
    IN(QueryWrapperConstants.IN, "in"), // 在
    NOT_IN(QueryWrapperConstants.NOT_IN, "notIn"), // 不在
    EXISTS(QueryWrapperConstants.EXISTS, "exists"),// 在
    NOT_EXISTS(QueryWrapperConstants.NOT_EXISTS, "notExists"),// 在
    ;

    String value;

    String name;

    QueryWrapperEnum(String value, String name) {
        this.value = value;
        this.name = name;
    }

    public static QueryWrapperEnum getByName(String name) {
        for (QueryWrapperEnum queryWrapperEnum : values()) {
            if (queryWrapperEnum.name.equalsIgnoreCase(name)) {
                return queryWrapperEnum;
            }
        }
        throw new IllegalArgumentException("Invalid enum type: " + name);
    }

    public static QueryWrapperEnum getByValue(String value) {
        for (QueryWrapperEnum queryWrapperEnum : values()) {
            if (queryWrapperEnum.value.equalsIgnoreCase(value)) {
                return queryWrapperEnum;
            }
        }
        throw new IllegalArgumentException("Invalid enum value: " + value);
    }
}
